package com.kedacom.demo.modb.movision.controller;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.kedacom.demo.modb.movision.model.Account;
import com.kedacom.demo.modb.movision.service.AccountService;

@Controller
@RequestMapping("/account")
public class AccountController {

	@Resource
	private AccountService accountService;

	@RequestMapping(value = "/list")
	public String list(Model model) {
		List<Account> accounts = accountService.listAll();
		model.addAttribute("accounts", accounts);
		return "account/list";
	}

	@RequestMapping(value = "/createPublic")
	public String toCreatePublic() {
		return "account/createPublic";
	}

	@RequestMapping(value = "/createPrivate")
	public String toCreatePrivate() {
		return "account/createPrivate";
	}

	@RequestMapping(value = "/save", method = RequestMethod.POST)
	public String save(Account account) {
		accountService.createAccount(account);
		return "redirect:list";
	}

}
